package com.jianbing.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jianbing.entity.Result;
import com.jianbing.service.OrderService;
import com.jianbing.util.IPUtil;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/order")
public class OrderController {

	Logger logger = Logger.getLogger(OrderController.class);

	@Autowired
	private OrderService orderService;

	@RequestMapping(value = "/getOrderSn", method = RequestMethod.POST)
	@ResponseBody
	public Result getOrderSn(HttpServletRequest request, HttpServletResponse response, @RequestBody String body) {
		Result result = new Result();
		logger.info("获取订单号---" + body);
		try {
			JSONObject json = JSONObject.fromObject(body);
			String accessIp = IPUtil.getIpAddr(request);
			return orderService.getOrderSn(json, result, accessIp);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result.setCode(-1);
			result.setMsg("系统异常");
			return result;
		}
	}
}
